package Java8;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.DoubleBinaryOperator;
import java.util.function.Function;
import java.util.function.IntToLongFunction;
import java.util.stream.Collectors;

public class DishTest {

    public static void main(String[] args) {
        List<Dish> menu = new ArrayList<>();

        menu.add(new Dish("pork", false, 800, Type.FISH));
        menu.add(new Dish("pork2", false, 333, Type.FISH));
        menu.add(new Dish("beef", false, 700, Type.MEAT));
        menu.add(new Dish("chicken", false, 400, Type.OTHER));
        List<String> lowCaloricCishesName = menu.stream().filter(d -> d.getCalories() < 400)
            .sorted(Comparator.comparing(Dish::getCalories)).map(Dish::getName)
            .collect(toList());

        System.out.println(menu.stream().collect(groupingBy(Dish::getType)));

        Function<Dish, String> functionTest = (Dish d) -> d.getName();
        BiFunction<Dish, Dish, Integer> dishDishIntegerBiFunction = (Dish d1, Dish d2) -> d1.getCalories() + d2.getCalories();

        System.out.println(dishDishIntegerBiFunction.apply(menu.get(0), menu.get(1)));
        System.out.println(functionTest.apply(menu.get(0)));

        BiConsumer<Dish, Dish> biConsumer = (Dish d1, Dish d2) -> System.out.println("biconsumersss" + d1.getCalories() + d2.getCalories());

        BiConsumer<Dish, Integer> biConsumer1 = (Dish d1, Integer i1) -> System.out.println("biconsumersss2" + d1.getCalories() + i1);

        biConsumer.accept(menu.get(0), menu.get(1));

        biConsumer1.accept(menu.get(0), 99999);

        menu.stream().map((Dish e) -> {
            return e.getName();
        });

        BinaryOperator<Dish> binaryOperator = (Dish d1, Dish d2) -> d1;
        binaryOperator.apply(menu.get(0), menu.get(1));

        DoubleBinaryOperator doubleBinaryOperator = (double d1, double d2) -> d1 + d2;

        System.out.println(doubleBinaryOperator.applyAsDouble(111, 222));

        IntToLongFunction intToLongFunction = (int i) -> i + 100;
        intToLongFunction.applyAsLong(2222);

    }
}
